package com.fire.eyes.service.impl;

import java.util.HashMap;
import java.util.Map;

import com.fire.eyes.constants.ErrorCodeConstants;
import com.fire.eyes.dao.TMitMaketContentMapper;
import com.fire.eyes.model.TMitMaketContent;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.fire.core.util.AjaxResult;
import com.fire.core.util.BlogUtil;
import com.fire.eyes.service.ITMitMaketContentService;

import net.sf.json.JSONObject;

/**
 * <p>
 * 营销内容表 服务实现类
 * </p>
 *
 * @author MIT123
 * @since 2018-06-08
 */
@Service
public class TMitMaketContentServiceImpl extends ServiceImpl<TMitMaketContentMapper, TMitMaketContent> implements ITMitMaketContentService {
	private static Logger LOGGER = Logger.getLogger(TMitMaketContentServiceImpl.class);

	@Autowired
	private TMitMaketContentMapper contentMapper;
	@Override
	public AjaxResult queryMarketcontent(String json) {
		Map<String,String> map = new HashMap<String,String>();
		JSONObject obj = JSONObject.fromObject(json);
		String uuid = obj.getString("uuid");
		if(StringUtils.isBlank(uuid)) {
			return new AjaxResult(ErrorCodeConstants.CONTENTID_ISNULL,"内容ID不能为空","内容ID不能为空");
		}
		BlogUtil.inlog(json, "", "mit/goods/marketcontent", "marketcontent", "req");
		TMitMaketContent maketContent = contentMapper.selectById(uuid);
		if(null != maketContent) {
			if("0".equals(maketContent.getStatus()) || "2".equals(maketContent.getStatus())) {
				if("2".equals(maketContent.getStatus())) {
					LOGGER.info("内容状态为审核中");
					return new AjaxResult(ErrorCodeConstants.CONTENT_ISNOTEXIST,"获取失败，内容审核中","获取失败，内容审核中");
				}else if("0".equals(maketContent.getStatus())){
					LOGGER.info("内容状态为编辑中");
					return new AjaxResult(ErrorCodeConstants.CONTENT_ISNOTEXIST,"获取失败，内容编辑中","获取失败，内容编辑中");

				}
			}
			map.put("contextid", maketContent.getContextid());
			map.put("contentname", maketContent.getContentname());
			String content = StringEscapeUtils.unescapeHtml(maketContent.getContent().replaceAll("& ", "&"));
			map.put("content", content);
			AjaxResult ajaxResult = new AjaxResult(ErrorCodeConstants.SUCCESS,"获取成功",map,"获取成功");
			String jsonString = JSONObject.fromObject(ajaxResult).toString();
			BlogUtil.inlog(jsonString, "", "mit/goods/marketcontent", "marketcontent", "resp");
			return ajaxResult;
		}else {
			return new AjaxResult(ErrorCodeConstants.CONTENT_ISNOTEXIST,"获取失败","获取失败");
		}
	}
}
